from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-13 14:04:11.827856
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 13, Dec, 2021
Time: 14:04:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.4743
Nobs: 504.000 HQIC: -47.9326
Log likelihood: 5807.24 FPE: 1.13428e-21
AIC: -48.2283 Det(Omega_mle): 9.50442e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.362308 0.079737 4.544 0.000
L1.Burgenland 0.098703 0.044124 2.237 0.025
L1.Kärnten -0.115840 0.022667 -5.110 0.000
L1.Niederösterreich 0.174654 0.091340 1.912 0.056
L1.Oberösterreich 0.129954 0.092530 1.404 0.160
L1.Salzburg 0.281844 0.047365 5.950 0.000
L1.Steiermark 0.021134 0.061158 0.346 0.730
L1.Tirol 0.107624 0.049386 2.179 0.029
L1.Vorarlberg -0.084387 0.043534 -1.938 0.053
L1.Wien 0.030241 0.083073 0.364 0.716
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.019712 0.176473 0.112 0.911
L1.Burgenland -0.052274 0.097654 -0.535 0.592
L1.Kärnten 0.036043 0.050167 0.718 0.472
L1.Niederösterreich -0.214995 0.202154 -1.064 0.288
L1.Oberösterreich 0.472211 0.204788 2.306 0.021
L1.Salzburg 0.312737 0.104827 2.983 0.003
L1.Steiermark 0.102400 0.135354 0.757 0.449
L1.Tirol 0.310730 0.109300 2.843 0.004
L1.Vorarlberg 0.008146 0.096350 0.085 0.933
L1.Wien 0.015876 0.183857 0.086 0.931
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.223426 0.040609 5.502 0.000
L1.Burgenland 0.090017 0.022472 4.006 0.000
L1.Kärnten -0.005033 0.011544 -0.436 0.663
L1.Niederösterreich 0.222350 0.046518 4.780 0.000
L1.Oberösterreich 0.168767 0.047125 3.581 0.000
L1.Salzburg 0.036764 0.024122 1.524 0.127
L1.Steiermark 0.026509 0.031147 0.851 0.395
L1.Tirol 0.076616 0.025151 3.046 0.002
L1.Vorarlberg 0.055515 0.022172 2.504 0.012
L1.Wien 0.106539 0.042308 2.518 0.012
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161466 0.039684 4.069 0.000
L1.Burgenland 0.041854 0.021960 1.906 0.057
L1.Kärnten -0.012743 0.011281 -1.130 0.259
L1.Niederösterreich 0.151754 0.045459 3.338 0.001
L1.Oberösterreich 0.345028 0.046052 7.492 0.000
L1.Salzburg 0.100766 0.023573 4.275 0.000
L1.Steiermark 0.108907 0.030438 3.578 0.000
L1.Tirol 0.087257 0.024579 3.550 0.000
L1.Vorarlberg 0.053317 0.021667 2.461 0.014
L1.Wien -0.038087 0.041345 -0.921 0.357
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156033 0.076121 2.050 0.040
L1.Burgenland -0.040864 0.042123 -0.970 0.332
L1.Kärnten -0.036568 0.021639 -1.690 0.091
L1.Niederösterreich 0.129058 0.087199 1.480 0.139
L1.Oberösterreich 0.188874 0.088335 2.138 0.033
L1.Salzburg 0.255496 0.045217 5.650 0.000
L1.Steiermark 0.075178 0.058385 1.288 0.198
L1.Tirol 0.131279 0.047146 2.784 0.005
L1.Vorarlberg 0.104362 0.041561 2.511 0.012
L1.Wien 0.040247 0.079307 0.507 0.612
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.082167 0.060270 1.363 0.173
L1.Burgenland 0.015193 0.033352 0.456 0.649
L1.Kärnten 0.051060 0.017133 2.980 0.003
L1.Niederösterreich 0.178317 0.069041 2.583 0.010
L1.Oberösterreich 0.338850 0.069941 4.845 0.000
L1.Salzburg 0.049800 0.035802 1.391 0.164
L1.Steiermark -0.005975 0.046227 -0.129 0.897
L1.Tirol 0.124747 0.037329 3.342 0.001
L1.Vorarlberg 0.058635 0.032906 1.782 0.075
L1.Wien 0.108889 0.062792 1.734 0.083
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169093 0.073098 2.313 0.021
L1.Burgenland 0.011604 0.040450 0.287 0.774
L1.Kärnten -0.060706 0.020780 -2.921 0.003
L1.Niederösterreich -0.113731 0.083735 -1.358 0.174
L1.Oberösterreich 0.234352 0.084826 2.763 0.006
L1.Salzburg 0.038057 0.043421 0.876 0.381
L1.Steiermark 0.263553 0.056065 4.701 0.000
L1.Tirol 0.488685 0.045274 10.794 0.000
L1.Vorarlberg 0.071166 0.039910 1.783 0.075
L1.Wien -0.099207 0.076156 -1.303 0.193
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.144940 0.080827 1.793 0.073
L1.Burgenland -0.014223 0.044727 -0.318 0.750
L1.Kärnten 0.063565 0.022977 2.766 0.006
L1.Niederösterreich 0.171087 0.092590 1.848 0.065
L1.Oberösterreich -0.075616 0.093796 -0.806 0.420
L1.Salzburg 0.222405 0.048013 4.632 0.000
L1.Steiermark 0.133926 0.061994 2.160 0.031
L1.Tirol 0.051726 0.050061 1.033 0.301
L1.Vorarlberg 0.141496 0.044130 3.206 0.001
L1.Wien 0.164644 0.084210 1.955 0.051
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.458013 0.044837 10.215 0.000
L1.Burgenland -0.001386 0.024811 -0.056 0.955
L1.Kärnten -0.013777 0.012746 -1.081 0.280
L1.Niederösterreich 0.178220 0.051362 3.470 0.001
L1.Oberösterreich 0.263384 0.052031 5.062 0.000
L1.Salzburg 0.019214 0.026634 0.721 0.471
L1.Steiermark -0.011359 0.034390 -0.330 0.741
L1.Tirol 0.071414 0.027770 2.572 0.010
L1.Vorarlberg 0.055997 0.024480 2.287 0.022
L1.Wien -0.018033 0.046713 -0.386 0.699
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.027471 0.092314 0.154527 0.139899 0.065719 0.081900 0.014080 0.208618
Kärnten 0.027471 1.000000 -0.035039 0.130590 0.049357 0.073733 0.455631 -0.081241 0.097085
Niederösterreich 0.092314 -0.035039 1.000000 0.281033 0.099890 0.253831 0.049919 0.142812 0.248337
Oberösterreich 0.154527 0.130590 0.281033 1.000000 0.194359 0.284814 0.159605 0.125750 0.186095
Salzburg 0.139899 0.049357 0.099890 0.194359 1.000000 0.120579 0.061247 0.109239 0.067791
Steiermark 0.065719 0.073733 0.253831 0.284814 0.120579 1.000000 0.131919 0.088156 0.007757
Tirol 0.081900 0.455631 0.049919 0.159605 0.061247 0.131919 1.000000 0.062599 0.126835
Vorarlberg 0.014080 -0.081241 0.142812 0.125750 0.109239 0.088156 0.062599 1.000000 -0.010190
Wien 0.208618 0.097085 0.248337 0.186095 0.067791 0.007757 0.126835 -0.010190 1.000000